package com.cskaoyan.dbutils;

import com.cskaoyan.vo.Account;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 创建日期: 2021/11/25 16:03
 *
 * @author ciggar
 */
public class MyResultSetHandler implements ResultSetHandler<Account> {

    // 其实就是把结果集解析为对象
    @Override
    public Account handle(ResultSet rs) throws SQLException {

        Account account = new Account();

        if (rs.next()) {

            int id = rs.getInt("id");
            String name = rs.getString("name");
            int money = rs.getInt("money");
            String role = rs.getString("role");

            account.setId(id);
            account.setName(name);
            account.setRole(role);
            account.setMoney(money);

        }
        return account;
    }
}
